package Operators;

import java.util.ArrayList;
import java.util.Vector;

import runner.DateBD;

import Route.Legatura;
import Route.Statie;
import States.StationState;
import Templates.Operator;

public class DrumOperator {

	private static ArrayList<Operator<Statie>> DOperators=new ArrayList<Operator<Statie>>();
	
	public static ArrayList<Operator<Statie>> returnOperators()
	{

		DOperators.add(new MoveToStation());

		return DOperators;
	}

	public static class InitialState implements Operator<Statie>
	{
		public String toString(){

			return "Initial State";
		}
	
		public int getOperatorNumber()
		{
			return 0;
		}			

		public Statie execute(Statie s)
		{
			return null;
		}

		public boolean available(Statie s)
		{
			return false;
	
		}
	}
	
	public static class MoveToStation implements Operator<Statie>
	{
		private Statie to = null;
		private int index = 0;
		private Vector<Statie> statii = new Vector<Statie>();
		
		public MoveToStation(){
			statii = statiiFinale(StationState.curenta);
		}
		
		public MoveToStation(Statie to){
			this.to = to;
		}
		
		public String toString(){
	
		return "Move there";
		}
		
		public int getOperatorNumber()
		{
			return 1;
		}		
	
		public Statie execute(Statie s)
		{
		StationState s2=new StationState(StationState.curenta);
		s2.setCurenta(to);
		return s2.getCurenta();
	}
	
	public boolean available(Statie s)
	{
		if(index < statii.size()) {
			to = statii.get(index);
			index++;
			return true;
		}
		return false;
	}
	
	public Vector<Statie> statiiFinale(Statie s){
		Vector<Statie> st = new Vector<Statie>();
		Legatura[] leg = DateBD.cl.toVector();
		for(int i = 0;i<leg.length;i++){
			if(leg[i].getStart() == s){
				st.add(leg[i].getEnd());
			}
		}
		return st;
	}
	}
}